#!/usr/bin/python
import json
import time
import os
import socket

from Dev_state import Dev
from server_json import Json_encoder,Json_decoder

print "Connecting ...",
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
print "done"

print "Connecting to remote host...",
s.connect(("127.0.0.1",50000))
print "done"


try:
    json_data1 = s.recv(4096)
except socket.error, e:
    time.sleep(0.5)
    print "Error receiving data  : %s" %e

data = Json_decoder().decode(json_data1)
print "Get from server : "    
print data
print "---"*8

try:
    data = Dev("Hello" ,"on").getDeviceInformation()
    json_data2 = Json_encoder().encode(data)
    print "send Data:"
    s.sendall(json_data2)
    print "Send ...ok"
except socket.error,e:
    time.sleep(0.5)
    print "error : %s "% e
        
s.close()
